import 'package:flutter/material.dart';
import 'package:flutter_2b_client/pages/UpdatePassworPage.dart';
import 'package:flutter_2b_client/store/EmployeeAuthorizationStore.dart';
import 'package:flutter_2b_client/utils/MobxHooks.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:provider/provider.dart';

class MinePage extends HookWidget {
  const MinePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var employeeAuthorizationStore =
        Provider.of<EmployeeAuthorizationStore>(context);
    var appVersionState = useState("");
    useEffect(() {
      PackageInfo.fromPlatform().then((value) => appVersionState.value = value.version);
    },[]);

    return Scaffold(
      appBar: AppBar(
        title: const Text("我的"),
        actions: [
          IconButton(
            onPressed: () async {
              await employeeAuthorizationStore.logOut();
              if(context.mounted) {
                context.replace("/logIn");
              }
            },
            icon: const Icon(Icons.logout),
            tooltip: "退出登录",
          ),
        ],
      ),
      body: ListView(
        children: [
          ListTile(
            title: const Text("修改密码"),
            leading: const Icon(Icons.security),
            trailing: const Icon(Icons.keyboard_arrow_right),
            onTap: () {
              context.push(UpdatePasswordPage.path);
            },
          ),
          ListTile(
            title: const Text("版本"),
            leading: const Icon(Icons.phone_android),
            trailing: Text(appVersionState.value),
          ),
        ],
      ),
    );
  }
}
